<?php

//print_r($_POST);
 
// username and password sent from form 
//print_r($_POST);


		$result=array();

		if(!isset($_POST['userid'])||!isset($_POST['orgid'])||!isset($_POST['inventorys'])){
			$result['stat']=0;
			echo json_encode($result);
	 		 return;
		}
		$inventorys=$_POST['inventorys'];
		$user1=$_POST['userid'];
		$source=$_POST['orgid'];
		
		//$target=$_POST['toorgid'];
		//runtimelog("target:".$target);
		$error=array();
		foreach($inventorys as $inv){
			$inv_id=$inv['hide'];
			$number=$inv['num2'];
			$target=$inv['toorgid'];
			$scan_code=$inv['scan_code'];
			$limit= inventory_limit($inv_id);
			if(!is_numeric($number)||$number==''){
				array_push($error,$scan_code);				
			}
			if($limit>=$number){				
				if(distributeItem($inv_id,$scan_code,$limit,$number,$source,$target,$user1)){
				}else{
				array_push($error,$scan_code);				
					
				}
			}else{
				array_push($error,$scan_code);				
			}
		}
		
		$result['stackedNum']=count($inventorys)-count($error);
		$result['failededNum']=count($error);
		$result['error']=$error;
		$result['stat']=1;
		echo json_encode($result);
	 	return;

?>